/**
 * [OElove] (C)2010-2099 OELOVE.COM Inc.biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/04/24 by CL $
*/
$(function(){

	//切换诚信查询
	$(document).on("click", "[f='but_credit_type']", function(){
		$_type = $(this).attr("data-type");
		$("[f='but_credit_type']").removeClass("current");
		$(this).addClass("current");
		
		$_text = "";
		if ($_type == "mobile") {
			$_text = "请输入查询手机号";
		}
		else if ($_type == "qq") {
			$_text = "请输入查询QQ号";
		}
		else if ($_type == "email") {
			$_text = "请输入查询邮箱";
		}
		else if ($_type == "weixin") {
			$_text = "请输入查询微信";
		}
		else if ($_type == "idcard") {
			$_text = "请输入查询身份证号";
		}
		else {
			$_text = "请输入查询关键词";
		}
		$("#credit_key").val("");
		$("#credit_key_pt").html($_text).show();
		$("#credit_type").val($_type);
		$("#credit_result").hide();
	});
	
	//查询
	$(document).on("click", "[f='but_check_credit']", function(){
		$_credit_flag = $(this).attr("data-flag");
		if ($_credit_flag == "0") {
			ToastShow("网站暂未开启该功能，请联系客服");
			return false;
		}
		$("#credit_loading").show();
		$("#credit_result").hide();
		$_keyword = $("#credit_key").val();
		$_type = $("#credit_type").val();
		if ($_keyword.length == 0) {
			ToastShow("请输入要查询的信息");
			$("#credit_loading").hide();
			return false;
		}
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?c=credit",
			cache: false,
			data: {a:"get", type:$_type, value:$_keyword, datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				$("#key_tips").html("“"+$_keyword+"”");
				$("#credit_img").removeClass("current");
				if ($response == "1") { //有被举报过
					$("#credit_img").addClass("current");
					$("#check_tips").html("有举报记录，可能存在风险");
				}
				else if ($response == "2") { //没有被举报过
					$("#credit_img").removeClass("current");
					$("#check_tips").html("记录良好，没有被举报过");
				}
				else { //查询失败
					$("#credit_img").addClass("current");
					$("#check_tips").html("信息查询失败");
				}
				$("#credit_result").show();
				$("#credit_loading").hide();
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
				$("#credit_loading").hide();
			}
		});

	});
	
	//弹出发布防骗文章
	$(document).on("click", "[f='but_safety_addto']", function(){
		if (_LOGIN_STATUS == 0) {
			_jdLogin();
			return false;
		}
		$_url = _ROOT_PATH+"index.php?c=safety&a=add&r="+get_rndnum(8);
		oeShadeBox("pop_addto_safety", "ajax", $_url, 550, 350);
	});

	//保存发布文章 AJAX
	$(document).on("click", "[f='but_save_safety']", function(){
		$safety_title = $("#safety_title").val();
		$safety_content = $("#safety_content").val();

		if ($safety_title.length == 0) {
			ToastShow("请填写标题");
			return false;
		}
		if ($safety_content.length == 0) {
			ToastShow("请填写内容");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?c=safety",
			cache: false,
			data: {
				a:"saveadd", title:$safety_title, content:$safety_content, r:get_rndnum(8)
			},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					_closeShadeBox("pop_addto_safety", function(){
						ToastShow("文章提交成功，请等待审核！");
					});

				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("提交失败");
					}
				}
			},
			error: function() {
				$tips_obj.html("系统繁忙，请稍后再试");
			}
		});
	});
	
});

